<%@ page import="id.co.gomobile.assessment.User" %>
<%@ page import="id.co.gomobile.assessment.Profile"%>
<%@ page import="id.co.gomobile.assessment.Role"%>

<%@page import="id.co.gomobile.assessment.Test"%>
<%@page import="org.joda.time.Period"%><html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="layout" content="main" />
        <title>User Details</title>
    </head>
    <body>
    <g:render template="/shared/navigation" />
    
    <div id="body">
    
    <h1>User Details</h1>

    <g:if test="${flash.message}">
        <div class="message">${flash.message}</div>
    </g:if>

    <div class="dialog">

    <fieldset>
 
            <h3>Login Information</h3>
            <div class="dialog">
                <table>
                    <col width="200px" />
                    <tbody>
                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="user.id.label" default="Id" /></td>
                            <td valign="top" class="value">${fieldValue(bean: userInstance, field: "id")}</td>
                        </tr>

                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="user.username.label" default="Username" /></td>
                            <td valign="top" class="value">${fieldValue(bean: userInstance, field: "username")}</td>
                        </tr>
                    
                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="user.email.label" default="Email" /></td>
                            <td valign="top" class="value">${fieldValue(bean: userInstance, field: "email")}</td>
                        </tr>
                    
                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="user.enabled.label" default="Enabled" /></td>
                            <td valign="top" class="value"><g:formatBoolean boolean="${userInstance?.enabled}" true="Yes" false="No" /></td>
                        </tr>

                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="user.administrator.label" default="Administrator" /></td>
                            <td valign="top" class="value"><g:formatBoolean boolean="${userInstance?.isAdministrator()}" true="Yes" false="No" /></td>
                        </tr>

                    </tbody>
                </table>
            </div>
            <br/>
            <h3>Personal Information</h3>
            <div class="dialog">
            <table>
                <col width="200px" />
                <tbody>
                    <tr class="prop">
                        <td valign="top" class="name"><g:message code="user.profile.fullname.label" default="Fullname" /></td>
                        <td valign="top" class="value">${fieldValue(bean: userInstance, field: "profile.fullname")}</td>
                    </tr>

                    <tr class="prop">
                        <td valign="top" class="name"><g:message code="user.profile.birthdate.label" default="Birthdate" /></td>
                        <td valign="top" class="value"><g:formatDate date="${userInstance.profile?.birthdate}" type="date" style="LONG" /></td>
                    </tr>

                    <tr class="prop">
                        <td valign="top" class="name"><g:message code="user.profile.gender.label" default="Gender" /></td>
                        <td valign="top" class="value">${fieldValue(bean: userInstance, field: "profile.gender")}</td>
                    </tr>

                    <tr class="prop">
                        <td valign="top" class="name"><g:message code="user.profile.address.label" default="Address" /></td>
                        <td valign="top" class="value">${fieldValue(bean: userInstance, field: "profile.address")}</td>
                    </tr>

                    <tr class="prop">
                        <td valign="top" class="name"><g:message code="user.profile.phone.label" default="Phone" /></td>
                        <td valign="top" class="value">${fieldValue(bean: userInstance, field: "profile.phone")}</td>
                    </tr>

                    <tr class="prop">
                        <td valign="top" class="name"><g:message code="user.profile.description.label" default="Description" /></td>
                        <td valign="top" class="value">${fieldValue(bean: userInstance, field: "profile.description")}</td>
                    </tr>
                </tbody>
            </table>
            </div>
 
         <br/>

        <div class="buttons">
            <g:form>
                <g:hiddenField name="id" value="${userInstance?.id}" />
                <span class="button"><g:actionSubmit class="edit" action="edit" value="${message(code: 'default.button.edit.label', default: 'Edit')}" /></span>
                <span class="button"><g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" /></span>
            </g:form>
        </div>
        
    </fieldset>


    <br/>
    
    <fieldset>
        
        <h3>Assign a Test</h3>
        
        <g:form controller="assignment" action="save" method="post" >
        <g:hiddenField name="user.id" value="${userInstance?.id}" />
                
        <div class="form">
        <div class="value">
            <g:select name="test.id" from="${Test.list()}" optionKey="id" optionValue="name" value="${itemInstance?.test?.id}" />
        </div>

        <br/>
        <div class="buttons">
            <span class="button"><g:submitButton name="submit" class="save" value="${message(code: 'default.button.submit.label', default: 'Submit')}" /></span>
        </div>

        </div>
        </g:form>
        
        
        <g:if test="${assignmentInstanceList}">
        <br/>
        <br/>

        <h3>Assignment List</h3>
        
	    <div class="list">
	    <table>
	        <col width="50" />
	        <col />
	        <col width="175" />
	        <col width="100" />
	        <col width="150" />
	        <col width="150" />
	        <thead>
	            <tr>
	                <th colspan="6" align="right">${assignmentInstanceList.size()} displayed</th>
	            </tr>
	            <tr>
	                <g:sortableColumn property="id" params="${params}" title="${message(code: 'assignment.id.label', default: 'Id')}" />
	                <th title="Test">Test</th>
	                <g:sortableColumn property="endTime" params="${params}" title="${message(code: 'assignment.endTime.label', default: 'End Time')}" />
	                <th title="Time Taken">Time Taken</th>
	                <g:sortableColumn property="total" params="${params}" title="${message(code: 'assignment.total.label', default: 'Total Point')}" />
	                <th title="Action">Action</th>
	            </tr>
	        </thead>
	        <tbody>
	        <g:each in="${assignmentInstanceList}" status="i" var="assignmentInstance">
	            <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
	                <td>${fieldValue(bean: assignmentInstance, field: "id")}</td>
	                <td><g:link controller="test" action="show" id="${assignmentInstance?.test?.id}">${assignmentInstance?.test?.name}</g:link></td>
	                <td><g:formatDate date="${assignmentInstance?.endTime}" type="datetime" style="MEDIUM" timeStyle="MEDIUM"/></td>
	                <td align="center">
	                   <% Period period = new Period(assignmentInstance?.startTime?.time, assignmentInstance?.endTime?.time) %>
	                   ${period.getHours()}:${period.getMinutes()}:${period.getSeconds()}
	                </td>
	                <td align="center"><strong>${assignmentInstance?.total.asType(int)} of ${assignmentInstance?.items?.size()} (${(assignmentInstance?.items?.size() > 0 ? ((assignmentInstance?.total?.asType(int) / assignmentInstance?.items?.size()) * 100) : 0).round(new java.math.MathContext(4))}%)</strong></td>
	                <td style="text-align: center">
	                    <g:form controller="assignment" action="show" id="${assignmentInstance?.id}" style="display: inline">
	                        <input type="image" src="${resource(dir:'images/skin', file:'database_table.png')}" alt="Show" />
	                    </g:form>
	                    &nbsp;
	                    <g:form controller="assignment" action="delete" id="${assignmentInstance?.id}" style="display: inline">
	                        <input type="image" src="${resource(dir:'images/skin', file:'database_delete.png')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" alt="Delete" />
	                    </g:form>
	                </td>
	            </tr>
	        </g:each>
	        </tbody>
	    </table>
	    </div>
	    
	    </g:if>
    </fieldset>


    </div>
    
    </div>
    </body>
</html>